/*Joseph A. Coll
Cleaning 2016 SPAE 
9/3/2021 */
use "G:\My Drive\Backup 08202022\Working Papers\Michaels Edited Volume\Election Policies Fraud Beliefs Confidence\Data and Methods\2016.dta", clear 
gen year = 2016

tab inputstate
tab inputstate, nol
rename inputstate state_fips
statastates, fips(state_fips)
replace state_name = proper(state_name)
 
*Voted
tab Q1
tab Q1, nol
recode Q1 (1/5=0 "Did not vote") (6=1 "Voted"), gen(voted)
label var voted Voted

*Reason for not voting, second reason
*tab Q2

*First time voters
tab Q3
tab Q3, nol
recode Q3 (1 9=1 "First Time Voter") (2=0 "Not First Time Voter") (3=1), gen(voted_first_time)
label var voted_first_time "First Time Voter"

*Mode of voting 
tab Q4 
tab Q4 , nol
recode Q4 (1=1 "Voted on Election Day") (2=2 "Voted Prior to Election-Day") ///
(3=3 "Voted Absentee/Mail") (4 9/99=.), gen(voted_how)
label var voted_how "How Respondent Voted"

recode Q4 (1/2=1 "Voted in Person") (3=0 "Voted by Mail/Absentee") (4/99=1), gen(voted_inperson)
label var voted_inperson "Voted In-Person"

recode Q4 (1=0 "Voted on Election Day") (2/3=1 "Voted Prior to Election-Day") ///
(4/99=0), gen(voted_earlymail)
label var voted_early "Voted Early/Mail"

recode Q4 (1 3=0 "Voted on Election Day/Mail") (2=1 "Voted Early") ///
(4 9/99=0), gen(voted_early)
label var voted_early "Voted Early"

recode Q4 (1/2=0 "Did not Vote by Mail") (3=1 "Voted by Mail") ///
(4/99=0), gen(voted_mail)
label var voted_mail "Voted by Mail"

recode Q4 (1=1 "Election Day") (2 3=0 "After Election Day") (4/99=0), gen(voted_ed)
label var voted_ed "Voted on Election Day"

*Difficutly Finding Polling Place
tab Q5
tab Q5, nol
recode Q5 (1=4 "Very Difficult") (2=3 "Somewhat Difficult") (3=2 "Fairly Easy") ///
(4=1 "Very Easy") (5/99=1), gen(difficulty_finding_poll)
label var difficulty_finding_poll "Difficulty Finding Polling Place"

*Polling place type
tab Q6
recode Q6 (1=1 "Private Business") (2=2 "School") (3=3 "Church") (4=4 "Police/Fire Station") ///
(5=5 "Store/Mall") (6=6 "Senior Center") (7=7 "Community Center") (8=8 "Library") ///
(9=9 "Sports Arena") (10=10 "Gov't Office") (11=11 "Other") (9/999=.), gen(poll_type)
label var poll_type "Type of Polling Place"

*Knew who checked you in
tab Q7
recode Q7 (1=1 "Yes") (2/9=0 "No") (9/99=.), gen(knew_checkin_worker)
label var knew_checkin "Knew the Check-in Worker"

*Polling place run evaluation
tab Q8
sum Q8 if Q8 < 5
recode Q8 (1=4 "Very Well") (2=3 "Okay") (3=2 "Not Well") (4=1 "Terrible") ///
(9/99=.), gen(poll_eval4)
label var poll_eval4 "Poll Place Eval."

recode Q8 (1=3 "Very Well") (2=2 "Okay") (3/4=1 "Not Well") ///
(9/99=.), gen(poll_eval3)
label var poll_eval3 "Poll Place Eval."

*Voter registration problem
tab Q9
tab Q9, nol
recode Q9 (1=1 "Yes") (2/9=0 "No") (3/99=0) (.=0), gen(reg_problem)
label var reg_problem "Reg. Problems"

*Time voted
tab Q10
recode Q10 (1=1 "Before 5 AM") (2=2 "5-6 AM") (3=3 "6-7 AM") (4=4 "7-8 AM") ///
(5=5 "8-9 AM") (6=6 "9-10 AM") (7=7 "10-11 AM") (8=8 "11-12 PM") (9=9 "12-1 PM") ///
(10=10 "1-2 PM") (11=11 "2-3 PM") (12=12 "3-4 PM") (13=13 "4-5 PM") (14=14 "5-6 PM") ///
(15=15 "6-7 PM") (16=16 "7-8 PM") (17=17 "8-9 PM") (18=18 "After 9 PM") (9/999=.) ///
, gen(voted_time18)
labe var voted_time18 "Time Voted"

recode Q10 (1/4=1 "Before 8 AM") (5=2 "8-9 AM") (6=3 "9-10 AM") (7=4 "10-11 AM") ///
(8=5 "11-12 PM") (9=6 "12-1 PM") (10=7 "1-2 PM") (11=8 "2-3 PM") (12=9 "3-4 PM") ///
(13=10 "4-5 PM") (14/18=11 "After 5 PM") (9/999=.) ///
, gen(voted_time11)
labe var voted_time11 "Time Voted"

gen voted_time9_12 = 1 if voted_time11 >2 | voted_time11  <6 
replace voted_time9_12 = 0 if voted_time11 <3 | voted_time11 >5
label var voted_time9_12 "Morning Voter"

*Polling place closed
tab Q11
recode Q11 (1=0 "Open") (2=1 "Closed") (9/99=.), gen(poll_closed)
label var poll_closed "Polling Place was Closed"

*How voting fit into schedule
tab Q12

*Errands and voting
*tab Q12a

*Wait time
tab Q13
tab Q13, nol
recode Q13 (1=1 "No wait") (2=2 "<10 Min.") (3=3 "10-30 Min.") (4=4 "30-60 Min.") ///
(5=5 ">60 Min.") (9/99=.), gen(wait_time5)
label var wait_time5 "Wait Time"

recode Q13 (1=1 "No wait") (2=2 "<10 Min.") (3=3 "10-30 Min.") (4/5 =4 ">30 Min.") ///
(6/99=1), gen(wait_time4)
label var wait_time4 "Wait Time"
tab wait_time4 

*Where wait occurred
tab Q14
tab Q14  
recode Q14 (1=1 "Check In") (2=3 "Voting Queue") (3=2 "Evenly Split") (9/99=.) ///
, gen(wait_where_happened3)
recode Q14 (1=0 "Check In") (2/3=1 "Voting Queue") (9/99=.) ///
, gen(wait_where_happened2)
sum wait_where_happened3 wait_where_happened2

*Showed ID
tab Q15
tab Q15 if Q15 != 99
recode Q15 (1=0 "Gave Name/Address") (2/7=1 "Proved ID") (8 9/99=.), gen(proved_id)
label var proved_id "Proved Identification"

recode Q15 (1/2=0 "Showed No ID") (3/7=1 "Showed ID") (8 9/99=.), gen(showed_id)
label var showed_id "Showed Identification"

*Asked for ID
tab Q16
gen asked_photo  = 1 if Q16 ==1 
replace asked_photo  = 0 if asked_photo   != 1 & Q4 <8
labe var asked_photo  "Asked for Photo ID"
tab asked_photo 

*Voting machine problem
tab Q17, nol
recode Q17 (1=1 "Yes") (2/9=0 "No") (9/99=0) (.=0), gen(machine_problem)
label var machine_problem "Voting Problems"

*Poll worker eval
tab Q18, nol
recode Q18 (1=4 "Excellent") (2=3 "Good") (3=2 "Fair") (4=1 "Poor") (5/99=.), gen(pollworker_eval4)
label var pollworker_eval4 "Poll Worker Eval."
tab pollworker_eval4

recode Q18 (1=3 "Excellent") (2=2 "Good") (3/4=1 "Fair") (5/99=.), gen(pollworker_eval3)
label var pollworker_eval3 "Poll Worker Eval."
tab pollworker_eval3 

*Poll worker race
tab Q19
recode Q19 (1/3 5/6 9=1 "Non-White Poll Worker") (4=0 "White Poll Worker") ///
(8/99=.), gen(pollworker_race)
label var pollworker_race "Poll Worker Race"
tab pollworker_race

*Poll worker age
tab Q20 
tab Q20 , nol
recode Q20 (1=1 "<30") (2=2 "31-50") (3=3 "51-70") (4=4 "70+") (5/99=.), gen(pollworker_age)
label var pollworker_age "Poll Worker Age"

*confidence in own vote count
tab Q33
tab Q33, nol
recode Q33 (1=4 "Very Confident") (2=3 "Somewhat Confident") (3=2 "Not too Confident") ///
(4=1 "Not at All Confident") (5/99=.), gen(confidence_ownvote)
label var confidence_ownvote "Confidence Own Vote Counted Correctly"

*confidence in county vote count
tab Q34
tab Q34, nol
recode Q34 (1=4 "Very Confident") (2=3 "Somewhat Confident") (3=2 "Not too Confident") ///
(4=1 "Not at All Confident") (5/99=.), gen(confidence_countyvote)
label var confidence_countyvote "Confidence Local Votes Counted Correctly"

*confidence in state vote count
tab Q35
recode Q35 (1=4 "Very Confident") (2=3 "Somewhat Confident") (3=2 "Not too Confident") ///
(4=1 "Not at All Confident") (5/99=.), gen(confidence_statevote)
label var confidence_statevote "Confidence State Votes Counted Correctly"

clonevar confidence_statevote_original = Q35 

*confidence in natl vote count
tab Q36
recode Q36 (1=4 "Very Confident") (2=3 "Somewhat Confident") (3=2 "Not too Confident") ///
(4=1 "Not at All Confident") (5/99=.), gen(confidence_natlvote)
label var confidence_natlvote "Confidence National Votes Counted Correctly"
*Generate Binary Variables
	gen  confidence_ownvote_binary =1 if  confidence_ownvote >3
	replace confidence_ownvote_binary = 0 if confidence_ownvote < 4
	
	gen  confidence_countyvote_binary =1 if  confidence_countyvote >3
	replace confidence_countyvote_binary = 0 if confidence_countyvote < 4
	
	gen  confidence_statevote_binary =1 if  confidence_statevote >3
	replace confidence_statevote_binary = 0 if confidence_statevote < 4
	
	gen  confidence_natlvote_binary =1 if  confidence_natlvote >3
	replace confidence_natlvote_binary = 0 if confidence_natlvote < 4
	

*Voter Fraud Scale
*Q37A Q37B Q37C Q37D Q37E Q37F Q38 Q39
*Fraud
	*Vote multiple times
	tab Q37A 
	tab Q37A, nol
	recode Q37A (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ), gen(fraud_voter)
	label var fraud_voter "Repeat Voting"
	tab fraud_voter
	
	recode Q37A (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_voter_binary)
	label var fraud_voter_binary "Repeat Voting"
	tab fraud_voter_binary

	*Steal ballots
	tab Q37B 
	tab Q37B, nol
	recode Q37B (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ), gen(fraud_tamper)
	label var fraud_tamper "Tampering with Casr Ballots"
	tab fraud_tamper

	recode Q37B (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_tamper_binary)
	label var fraud_tamper_binary "Vote Theft"
	tab fraud_tamper_binary

	*Impersonation
	tab Q37C
	tab Q37C, nol
	recode Q37C (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ),gen(fraud_impersonation)
	label var fraud_impersonation "Voter Impersonation"
	tab fraud_impersonation

	recode Q37C (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_impersonation_binary)
	label var fraud_impersonation_binary "Voter Impersonation"
	tab fraud_impersonation_binary

	*Non-Citizen voters
	tab Q37D
	tab Q37D, nol
	recode Q37D (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ), gen(fraud_noncitizen)
	label var fraud_noncitizen "Non-Citizen Voting"
	tab fraud_noncitizen

	recode Q37D (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_noncitizen_binary)
	label var fraud_noncitizen_binary "Non-Citizen Voting"
	tab fraud_noncitizen_binary

	*Illegal absentee 
	tab Q37E
	tab Q37E, nol
	recode Q37E (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ), gen(fraud_wrongabsentee)
	label var fraud_wrongabsentee "Absentee Impersonation"
	tab fraud_wrongabsentee

	recode Q37E (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_wrongabsentee_binary)
	label var fraud_wrongabsentee_binary "Absentee Impersonation"
	tab fraud_wrongabsentee_binary

	*Officials change count 
	tab Q37F
	tab Q37F, nol
	recode Q37F (1=5 "Very Common") (2=4 "Occasional") (3=2 "Infrequent") (4=1 "Never") ///
	(5/99 . =3 "Unsure" ), gen(fraud_officialscheat)
	label var fraud_officialscheat "Officials Change Vote Count"
	tab fraud_officialscheat

	recode Q37F (1/3 5 . =1 "Frequently") (4=0 "Almost Never"), gen(fraud_officialscheat_binary)
	label var fraud_officialscheat_binary "Absentee Impersonation"
	tab fraud_officialscheat_binary

	*Unsure of fraud indicator
	gen fraud_unsure = 1 if fraud_voter ==3 | fraud_tamper ==3 | ///
	fraud_impersonation ==3 | fraud_noncitizen ==3 | fraud_wrongabsentee ==3 ///
	| fraud_officialscheat==3 
	replace fraud_unsure  = 0 if fraud_unsure  != 1
	tab fraud_unsure  
	tab   fraud_voter fraud_unsure
	tab   fraud_tamper fraud_unsure
	tab   fraud_impersonation fraud_unsure
	tab   fraud_noncitizen fraud_unsure
	tab   fraud_wrongabsentee fraud_unsure
	tab   fraud_officialscheat fraud_unsure
	
	gen fraud_scale = fraud_voter + fraud_tamper + fraud_impersonation + ///
	fraud_noncitizen + fraud_wrongabsentee + fraud_officialscheat
	replace fraud_scale = fraud_scale - 6
	replace fraud_scale = fraud_scale/6
	label var fraud_scale  "Fraud Belief Scale"
	tab fraud_scale 

	gen voter_fraud_scale = fraud_voter + fraud_impersonation + ///
	fraud_noncitizen + fraud_wrongabsentee 
	tab voter_fraud_scale 
	replace voter_fraud_scale = voter_fraud_scale - 4
	*replace voter_fraud_scale = voter_fraud_scale/4
	replace voter_fraud_scale = voter_fraud_scale/16
	replace voter_fraud_scale = voter_fraud_scale * 100 
	label var voter_fraud_scale  "Voter Fraud Belief Scale"
	tab voter_fraud_scale 

	gen election_fraud_scale =  fraud_tamper + fraud_officialscheat
	tab election_fraud_scale 
	replace election_fraud_scale = election_fraud_scale - 2
	replace election_fraud_scale = election_fraud_scale/2
	label var election_fraud_scale  "Election Fraud Belief Scale"
	tab election_fraud_scale 

*Reform proposals
tab Q44A 
tab Q44A, nol
local vars Q44A Q44B Q44C Q44D Q44E Q44F Q44G Q44H Q44I Q44J Q44K
foreach x of local vars {
recode `x' (1=3 "Strongly Support") (2=2 "Somewhat Support") (3=1 "Somewhat Oppose") ///
(4=0 "Strongly Oppose") (8 9/99=.) , gen(`x'_recode)
}
 
          
label var Q44A_recode "Support for Internet Voting"
label var Q44B_recode "Support for Cell-Phone Voting"
label var Q44C_recode "Support for All-Mail Elections"
label var Q44D_recode "Support for Auto-Register at 18"
label var Q44E_recode "Support for Election-Day Registration"
label var Q44F_recode "Support for Voter ID"
label var Q44G_recode "Support for Paper Back-Up at Machines"
label var Q44H_recode "Support for Weekend Election-Day"
label var Q44I_recode "Support for Election-Day as Holiday"
label var Q44J_recode "Support for Non-Partisan Election Official Selection"
label var Q44K_recode "Support for Auto-Register After Moving" 

rename  Q44A_recode    support_internet_voting
rename  Q44B_recode    support_cellphone_voting
rename  Q44C_recode   support_allmail
rename  Q44D_recode   support_autoreg_18
rename  Q44E_recode    support_edr
rename  Q44F_recode    support_vid
rename  Q44G_recode    support_paperbackup
rename  Q44H_recode   support_weekend_ed
rename  Q44I_recode    support_holiday_ed
rename  Q44J_recode    support_nonpartisan_leo
rename  Q44K_recode    support_autoreg_move

*Residency Length
tab time_1,
tab time_1, nol
recode time_1 (51/99=51 ">50 Years"), gen(residency_length)
labe var residency_length "Residency Length"

*gender
tab gender
tab gender, nol
recode gender (1=0 "Male") (2=1 "Female"), gen(female)
label var female Female

*race
tab race
tab race, nol
recode race (1=1 "White") (2/8=0 "Not White"), gen(white_non_hispanic)
label var white_non_hispanic "White"

recode race (2=1 "Black") (1 3/8=0 "Not Black"), gen(black_non_hispanic)
label var black_non_hispanic "Black"

	tab hispanic
	rename hispanic hispanic_original 
	
recode race (3=1 "Hispanic") (1 2 4/8=0 "Not Hispanic"), gen(hispanic)
label var hispanic "Hispanic"

recode race (4/8=1 "Other") (1/3=0 "Not Other"), gen(other_non_hispanic)
label var other_non_hispanic "Other"
	
*Age
tab birthyr
gen age = 2016-birthyr
label var age Age

gen age2 = age * age
label var age2 "Age SQuared"

*Education
tab educ
rename educ educ_precode
recode educ (1/2=1 "HS/Less") (3=2 "Some College") (4=3 "Assoc.") (5=4 "Bach.") ///
(6=5 "Adv."), gen(educ)
label var educ Education

*Marital status
tab marstat
recode marstat (1=1 "Married") (2/6=0 "Not Married"), gen(married)
label var married Married

*Employment
tab employ
recode employ (1/2=1 "Employed") (3/98=0 "Unemployed"), gen(employed)
label var employed Employed

*Income
tab faminc
tab faminc, nol
recode faminc (12/16=12) (31/97=.), gen(income_mean)
sum income_mean 
replace income_mean = 6 if income_mean == .
label var income_mean "Income"

*PID
tab pid3 
tab pid3, nol
recode pid3 (1=1 "Democrat") (2=3 "Republican") (3/5=2 "Independent"), gen(pid3_recode)
label var pid3_recode Partisanship
tab pid3_recode

recode pid3 (1=1 "Democrat") (2/5=0 "Not Democrat"), gen(dem)
label var dem Democrat

recode pid3 (2=1 "Republican") (1 3/5=0 "Not Republican"), gen(rep)
label var rep Republican

recode pid3 (3/5=1 "Independent") (1/2=0 "Not Independent"), gen(ind)
label var ind Independent

tab pid7 
tab pid7, nol
recode pid7 (1=1 "Strong Democrat") (2=2 "Moderate Democrat") (3=3 "Lean Democrat") ///
(4 8=4 "Independent") ///
(5=5 "Lean Republican") (6=6 "Moderate Republican") (7=7 "Strong Republican"), gen(pid7_recode)
label var pid7_recode Partisanship
tab pid7_recode

recode pid7 (1=1 "Strong Democrat") (2/8=0 "Not Strong Democrat"), gen(dem_strong) t
label var dem_strong "Strong Democrat"

recode pid7 (2=1 "Moderate Democrat") (1 3/8=0 "Not Moderate Democrat"), gen(dem_mod) t
label var dem_mod "Moderate Democrat"

recode pid7 (3=1 "Lean Democrat") (1 2 4/8=0 "Not Lean Democrat"), gen(dem_lean) t
label var dem_lean "Lean Democrat"

recode pid7 (4 8=1 "Independent") (1/3 5/7=0 "Not Independent"), gen(ind_nolean) t
label var ind_nolean "Independent"

recode pid7 (5=1 "Lean Republican") (1/4 6/7=0 "Not Lean Republican"), gen(rep_lean) t
label var rep_lean "Lean Republican"

recode pid7 (6=1 "Moderate Republican") (1/5 7=0 "Not Moderate Republican"), gen(rep_mod) t
label var rep_mod "Moderate Republican"

recode pid7 (7=1 "Strong Republican") (1/6=0 "Not Strong Republican"), gen(rep_strong) t
label var rep_strong "Strong Republican"

gen rep_w_lean = 1 if pid7_recode >4
replace rep_w_lean = 0 if pid7_recode <5
label var rep_w_lean "Republican"

gen dem_w_lean = 1 if pid7_recode <4
replace dem_w_lean = 0 if pid7_recode >3
label var dem_w_lean "Democrat"

*Voted for winner
gen voted_for_winner = 1 if pid7_recode >4
replace voted_for_winner  = 0 if pid7_recode <5
label var voted_for_winner "Voted for Winner"


*Ideology
tab ideo5
recode ideo5 (1=5 "Very Liberal") (2=4 "Liberal") (3=3 "Moderate") ///
(4=2 "Conservative") (5=1 "Very Conservative") (6=3), gen(liberalism)
label var liberalism Liberalism

*Political interest
tab newsint
recode newsint (1=1 "High Interest") (2/98=0 "Low Interest"), gen(poli_int)
label var poli_int "Political Interest"
 
*Save
save "G:\My Drive\Backup 08202022\Working Papers\Michaels Edited Volume\Election Policies Fraud Beliefs Confidence\Data and Methods\2016 SPAE Cleaned.dta", replace


sum confidence_ownvote confidence_countyvote confidence_statevote confidence_natlvote /// DV
	      /// COVI
	voted_first_time wait_time4 voted_early reg_problem machine_problem difficulty_finding_poll /// Voting Exp.
	hispanic black_non_hispanic other_non_hispanic /// Race/Ethnicity
	age income_mean educ married female /// SES
	dem rep liberalism poli_int /// Poli Characteristics
	state_fips
	




